package org.jeecg.modules.online.cgform.converter.channel;

import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.online.cgform.converter.FieldCommentConverter;

import java.util.List;
import java.util.Map;

/**
 * 预知型值转换
 * 提前知道了当前数据可能需要替换的所有字典值
 */
public class ForeseeConvert  implements FieldCommentConverter {

    protected String filed;

    protected List<DictModel> dictList;

    public String getFiled() {
        return filed;
    }

    public void setFiled(String filed) {
        this.filed = filed;
    }

    public List<DictModel> getDictList() {
        return dictList;
    }

    public void setDictList(List<DictModel> dictList) {
        this.dictList = dictList;
    }


    @Override
    public String converterToVal(String txt) {
        if(oConvertUtils.isNotEmpty(txt)){
            for(DictModel model:this.dictList){
                if(model.getText().equals(txt)){
                    return model.getValue();
                }
            }
        }
        return null;
    }

    @Override
    public String converterToTxt(String val) {
        if(oConvertUtils.isNotEmpty(val)){
            for(DictModel model:this.dictList){
                if(model.getValue().equals(val)){
                    return model.getText();
                }
            }
        }
        return null;
    }

    @Override
    public Map<String, String> getConfig() {
        return null;
    }
}
